package com.google.code.jira.script.workflow;

import java.util.Map;

import org.apache.log4j.Category;
import org.apache.log4j.Logger;

import com.opensymphony.module.propertyset.PropertySet;
import com.opensymphony.workflow.InvalidInputException;
import com.opensymphony.workflow.Validator;
import com.opensymphony.workflow.WorkflowException;

public class ScriptValidator extends ScriptWorkflowUtils implements Validator {

	private static final Category log = Logger.getLogger(ScriptValidator.class);

	public void validate(Map transientVars, Map args, PropertySet ps) throws InvalidInputException, WorkflowException {
		// Evaluates the script and executes the method "passesCondition"
		Object returnObject = executeScript(transientVars, args, log);

		// Checks whether to throw or not an exception.
		if (returnObject != null) {
			throw new InvalidInputException(returnObject.toString());
		}
	}
}